﻿using System;
using System.Collections.Generic;
using System.Text;
using Android.App;
using Android.Content;
using Android.Util;
using Android.Widget;
using CometServiceDemo.Comet;
using CometServiceDemo.LocalComunication;

namespace CometServiceDemo
{
    [Application]
    public class GlobalApplication:Application
    {
        public GlobalApplication(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer)
            : base(handle, transfer)
        {
            //Current = this;
        }

        private static CommonServiceConnection<CometService> _cometServiceConnection;
        public static CommonServiceConnection<CometService> CometServiceConnection
        {
            get { return _cometServiceConnection; }
        }

        public override void OnCreate()
        {
            Log.Debug(this.GetType().ToString(), "Application is Starting....");
            base.OnCreate();
            //启动长连接服务
            var demoServiceIntent = new Intent("CometService");
            _cometServiceConnection = new CommonServiceConnection<CometService>();
            ApplicationContext.BindService(demoServiceIntent, _cometServiceConnection, Bind.AutoCreate);
            StartService(demoServiceIntent);
            Toast.MakeText(this, "Service Started", ToastLength.Short).Show();
            //启动自动更新服务
            //启动
        }
    }    
}
